package cn.home.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;
import cn.home.contract.domain.HomeContractInfo;
import cn.home.contract.service.IHomeContractInfoService;
import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 签约管理Controller
 * 
 * @author homedoctor
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/contractlog/contractlog")
public class HomeContractInfoController extends BaseController
{
    @Autowired
    private IHomeContractInfoService homeContractInfoService;

    /**
     * 查询签约管理列表
     */
    @PreAuthorize("@ss.hasPermi('contractlog:contractlog:list')")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<HomeContractInfo> list = homeContractInfoService.getHomeContractInfo();
        return getDataTable(list);
    }
    /**
     * 通过userId查询签约管理
     *  */
    @GetMapping("/selectByUserId/{userId}")
    public List<HomeContractInfo> selectByUserId(@PathVariable("userId") Long userId) {
        return homeContractInfoService.selectHomeContractInfoByUserId(userId);
    }

    /**
     * 导出签约管理列表
     */
    @PreAuthorize("@ss.hasPermi('contractlog:contractlog:export')")
    @Log(title = "签约管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeContractInfo homeContractInfo)
    {
        List<HomeContractInfo> list = homeContractInfoService.selectHomeContractInfoList(homeContractInfo);
        ExcelUtil<HomeContractInfo> util = new ExcelUtil<HomeContractInfo>(HomeContractInfo.class);
        util.exportExcel(response, list, "签约管理数据");
    }

    /**
     * 获取签约管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('contractlog:contractlog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(homeContractInfoService.selectHomeContractInfoById(id));
    }

    /**
     * 新增签约管理
     */
    @PreAuthorize("@ss.hasPermi('contractlog:contractlog:add')")
    @Log(title = "签约管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeContractInfo homeContractInfo)
    {
        return toAjax(homeContractInfoService.insertHomeContractInfo(homeContractInfo));
    }

    /**
     * 修改签约管理
     */
    @PreAuthorize("@ss.hasPermi('contractlog:contractlog:edit')")
    @Log(title = "签约管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeContractInfo homeContractInfo)
    {
        return toAjax(homeContractInfoService.updateHomeContractInfo(homeContractInfo));
    }

    /**
     * 删除签约管理
     */
    @PreAuthorize("@ss.hasPermi('contractlog:contractlog:remove')")
    @Log(title = "签约管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(homeContractInfoService.deleteHomeContractInfoByIds(ids));
    }
}
